import ToolConstant from "@/constant";
import ToolActionApi from "@/tool/http/tool-action.js";

let serverAppAction = ToolActionApi.init("function_server_app");

let serverAppDict = {};

serverAppAction.dict().then((dict) => {
  serverAppDict = dict;
});

// if (watchForm["enum_protocol_type"] === "TCP") {
//   // tempArray.push({ name: "__rules", memo: "转换规则", component: NtdDataTcpDetail })
// }

const rule = {
  queryParams: [],
  extendFields: [
    {
      name: "__serverAppId",
      memo: "服务应用",
      is: (watchForm) =>
        watchForm["enum_data_acquisition_type"] === "RULE_PASSIVE",
      dictListFun: () => serverAppDict,
    },
    {
      name: "__httpPath",
      memo: "访问路径",
      is: (watchForm) =>
        watchForm["enum_protocol_type"] === "HTTP" ||
        watchForm["enum_protocol_type"] === "HTTPS",
    },
    {
      name: "__httpType",
      memo: "请求类型",
      is: (watchForm) =>
        watchForm["enum_protocol_type"] === "HTTP" ||
        watchForm["enum_protocol_type"] === "HTTPS",
      dictList: ToolConstant.httpTypeDict,
    },
    {
      name: "__httpDataType",
      memo: "传参方式",
      is: (watchForm) =>
        watchForm["enum_protocol_type"] === "HTTP" ||
        watchForm["enum_protocol_type"] === "HTTPS",
      dictList: ToolConstant.httpDataType,
    },
    {
      name: "__httpResult",
      memo: "返回数据",
      is: (watchForm) =>
        watchForm["enum_data_acquisition_type"] === "RULE_PASSIVE",
    },
    {
      name: "__httpHost",
      memo: "请求主机",
      is: (watchForm) =>
        watchForm["enum_data_acquisition_type"] === "RULE_ACTIVE",
    },
    {
      name: "__httpPort",
      memo: "请求端口",
      is: (watchForm) =>
        watchForm["enum_data_acquisition_type"] === "RULE_ACTIVE",
    },
    {
      name: "__httpPath",
      memo: "请求路径",
      is: (watchForm) =>
        watchForm["enum_data_acquisition_type"] === "RULE_ACTIVE",
    },
    {
      name: "__httpLogicParams",
      memo: "逻辑参数",
      is: (watchForm) =>
        watchForm["enum_data_acquisition_type"] === "RULE_ACTIVE",
    },
    {
      name: "__httpParams",
      memo: "请求参数",
      is: (watchForm) =>
        watchForm["enum_data_acquisition_type"] === "RULE_ACTIVE",
    },
    {
      name: "__httpHeaders",
      memo: "header",
      is: (watchForm) =>
        watchForm["enum_data_acquisition_type"] === "RULE_ACTIVE",
    },
    {
      name: "__httpType",
      memo: "请求类型",
      is: (watchForm) =>
        watchForm["enum_data_acquisition_type"] === "RULE_ACTIVE",
      dictList: ToolConstant.httpTypeDict,
    },
    {
      name: "__httpDataType",
      memo: "传参方式",
      is: (watchForm) =>
        watchForm["enum_data_acquisition_type"] === "RULE_ACTIVE",
      dictList: ToolConstant.httpDataType,
    },
    {
      name: "__httpCron",
      memo: "请求周期(cron)",
      is: (watchForm) =>
        watchForm["enum_data_acquisition_type"] === "RULE_ACTIVE",
    },
  ],
  metaConfig: {
    id: {
      name: "id",
    },
  },
};

export default async function () {
  return rule;
}
